Skip to content

Conversation

@MohabCodeX
Copy link
Contributor

Problem

When events trigger other events (nested), the parent event would lose its cancellation reason and context.

Solution

Replaced single event context pointer with a proper context stack, each event now maintains its own cancellation state and reason.

Results

Before

[08:30:50] [debug] [testing]\vbug\server.lua:28 - Testing nested events...
[08:30:50] [debug] [testing]\vbug\server.lua:21 - PASS: Event B has its reason
[08:30:50] [debug] [testing]\vbug\server.lua:12 - FAIL: Expected 'Reason A', got ''

After

[08:30:50] [debug] [testing]\vbug\server.lua:28 - Testing nested events...
[08:30:50] [debug] [testing]\vbug\server.lua:21 - PASS: Event B has its reason
[08:30:50] [debug] [testing]\vbug\server.lua:12 - PASS: Event A kept its reason

Testing script
addEvent("eventA", true)
addEvent("eventB", true)

addEventHandler("eventA", root, function()
    cancelEvent(true, "Reason A")
    triggerEvent("eventB", root)
    
    local reason = getCancelReason()
    if reason == "Reason A" then
        outputDebugString("PASS: Event A kept its reason")
    else
        outputDebugString("FAIL: Expected 'Reason A', got '" .. reason .. "'")
    end
end)

addEventHandler("eventB", root, function()
    cancelEvent(true, "Reason B")
    
    local reason = getCancelReason()
    if reason == "Reason B" then
        outputDebugString("PASS: Event B has its reason")
    else
        outputDebugString("FAIL: Expected 'Reason B', got '" .. reason .. "'")
    end
end)

addCommandHandler("testevent", function()
    outputDebugString("Testing nested events...")
    triggerEvent("eventA", root)
end)

@MohabCodeX MohabCodeX marked this pull request as draft November 9, 2025 07:50
@MohabCodeX MohabCodeX marked this pull request as ready for review November 10, 2025 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant